package com.jm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jm.dao.ShoppingCartMapper;
import com.jm.pojo.ShoppingCart;
import com.jm.service.SetmealService;
import com.jm.service.ShoppingCartService;
import com.jm.service.ToyService;
import com.jm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 员工业务
 */
@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {

    @Autowired
    private ToyService toyService;
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private UserService userService;

    /**
     * 前端传入过来的购物车 信息为 名字 toyId setMealId 再根据用户id即可确定唯一的数据
     */
    @Override
    public ShoppingCart getShoppingCart(ShoppingCart shoppingCart, Long userId) {
        Long setmealId = shoppingCart.getSetmealId();
        Long toyId = shoppingCart.getToyId();
        LambdaQueryWrapper<ShoppingCart> qw = new LambdaQueryWrapper<>();
        qw.eq(true, ShoppingCart::getUserId, userId);
        qw.eq(shoppingCart.getSetmealId() != null, ShoppingCart::getSetmealId, setmealId);
        qw.eq(shoppingCart.getToyId() != null, ShoppingCart::getToyId, toyId);
        return getOne(qw);
    }

    @Override
    public boolean cleanShoppingCartByUserId(Long userId) {
        LambdaQueryWrapper<ShoppingCart> qw = new LambdaQueryWrapper<>();
        qw.eq(true, ShoppingCart::getUserId, userId);
        return remove(qw);

    }
}
